home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / editor / auror300.zip / MACHINE.ASM < prev    next >
Assembly Source File  |  1996-07-17  |  3KB  |  95 lines

  1. ;---------------------------------------------------------------------
  2. ; MACHINE.ASM
  3. ; Assembly Language Source for Machine.aml Examples
  4. ;
  5. ; This is an assembly language code sample called by the 'machine'
  6. ; function from within the Machine.aml macro. It shows how to access
  7. ; arguments passed by the macro language, and how to return values.
  8. ;
  9. ; The following arguments are passed to this assembly code from
  10. ; achine.amlL:
  11. ;
  12. ;   arg 1: a far pointer to a string
  13. ;   arg 2: a long numeric value
  14. ;   arg 3: a long numeric value passed by reference (a far pointer to
  15. ;          a long numeric value)
  16. ;
  17. ; This code will modify the first character of arg 1, replace the
  18. ; numeric value in arg 3 with arg 2 (returning arg 2 by reference), and
  19. ; return the previous contents of arg 3 as the return value of the
  20. ; 'machine' function. The Machine.aml macro will display the results.
  21. ;
  22. ; Machine.asm can be assembled and linked with the /T (TINY) option to
  23. ; generate a Machine.bin file. For example:
  24. ;
  25. ;   tasm machine.asm machine.obj
  26. ;   link /T machine.obj,machine.bin,,,,
  27. ;
  28. ; When Machine.aml is compiled, Machine.bin will be embedded in the
  29. ; resulting Machine.x executable macro file.
  30. ;-----------------------------------------------------------------------
  31.  
  32. _TEXT           segment byte
  33.                 assume  cs:_TEXT
  34.  
  35. String          equ      6 [bp]                 ; arg 1: string
  36. Numeric         equ     10 [bp]                 ; arg 2: number
  37. NumericRef      equ     14 [bp]                 ; arg 3: pointer to a number
  38.  
  39.                 push    bp                      ; only bp must be saved
  40.                 mov     bp,sp                   ; address the stack
  41.  
  42. ; On entry:
  43. ;               ax = number of arguments passed
  44. ;               bx = type mask
  45.  
  46. ; If the number of arguments passed is not equal to 3,
  47. ; fail and return the number of arguments passed.
  48.  
  49.                 cmp     ax,3
  50.                 je      start
  51.                 xor     dx,dx
  52.                 retf
  53. start:
  54.  
  55. ; Arg 1: String argument passed by reference
  56.  
  57. ; Note: strings are always passed by reference, whether or not the ref
  58. ; keyword is specified in the calling macro. If the string length is
  59. ; needed, it must be passed as a separate numeric argument. Strings are
  60. ; not automatically zero-terminated. If zero-terminated string is
  61. ; required, the binary zero should be added here or in the calling macro.
  62.  
  63.                 ; get far pointer to arg 1 and modify the first char
  64.                 les     di,dword ptr String
  65.                 mov     byte ptr es:[di],'!'
  66.  
  67. ; Arg 2: Numeric argument passed by value
  68. ; (numerics are always passed as long integers)
  69.  
  70.                 ; get the value of arg 2 in cx:bx
  71.                 mov     bx,Numeric
  72.                 mov     cx,Numeric + 2
  73.  
  74. ; Arg 3: Numeric argument passed by reference
  75.  
  76.                 ; get a far pointer to arg 3
  77.                 lds     si,dword ptr NumericRef
  78.  
  79.                 ; get the value of arg 3 in dx:ax
  80.                 mov     ax,ds:[si]
  81.                 mov     dx,ds:[si + 2]
  82.  
  83.                 ; return arg 2 by reference (in arg 3)
  84.                 mov     ds:[si],bx
  85.                 mov     ds:[si + 2],cx
  86.  
  87.                 ; restore bp
  88.                 pop     bp
  89.  
  90.                 ; return dx:ax (previous arg 3) to the 'machine' function
  91.                 retf
  92.  
  93. _TEXT           ends
  94.                 end
  95.